#include "stm32f10x.h"

#ifndef _GLOBALVARIABLE_H_
#define _GLOBALVARIABLE_H_

extern uint16_t Motor_Function_ChooseMode;
extern uint16_t Motor_Function_TryMode;
extern uint16_t Motor_Function_Control;
extern int16_t Motor_Function_TorqueCompensation;
extern uint16_t Motor_Function_MaxAngleAdd;
extern uint16_t Motor_Function_MinAngleDec;
extern uint16_t Motor_Function_AutoGroup;
extern uint16_t Motor_Function_AlarmSwitch;

extern uint16_t Motor_Function_CurrentTorque;
//extern int16_t Motor_Function_CurrentTorque;
extern uint16_t Motor_Function_CurrentSpeed;
extern uint16_t Motor_Function_CurrentSpeed1;
extern uint16_t Motor_Function_CurrentTurns;
extern uint16_t Motor_Function_CompleteStatus;
extern uint16_t Motor_Function_AlarmMessage;

extern uint16_t Motor_Function_ResetParameter;
extern uint16_t Motor_Function_SaveParameter;
///////////////////////////////////////////////////////////////////////
extern uint16_t Motor_Jog_PSpeed;
extern uint16_t Motor_Jog_RSpeed;
extern uint16_t Motor_Jog_Trypeed;
extern uint16_t Motor_Jog_PTurns;
extern uint16_t Motor_Jog_RTurns;
extern uint16_t Motor_Jog_TryTurns;
extern uint16_t Motor_Jog_TorqueSet;
extern uint16_t Motor_Jog_TryTorqueSet;
extern uint16_t Motor_Jog_StopTime;
///////////////////////////////////////////////////////////////////////
extern uint16_t Motor_Auto_FinalStopTime;

extern uint16_t Motor_Auto_Torque1;
extern uint16_t Motor_Auto_Turns1;
extern uint16_t Motor_Auto_Direction1;
extern uint16_t Motor_Auto_Speed1;

extern uint16_t Motor_Auto_Torque2;
extern uint16_t Motor_Auto_Turns2;
extern uint16_t Motor_Auto_Direction2;
extern uint16_t Motor_Auto_Speed2;

extern uint16_t Motor_Auto_Torque3;
extern uint16_t Motor_Auto_Turns3;
extern uint16_t Motor_Auto_Direction3;
extern uint16_t Motor_Auto_Speed3;

extern uint16_t Motor_Auto_Torque4;
extern uint16_t Motor_Auto_Turns4;
extern uint16_t Motor_Auto_Direction4;
extern uint16_t Motor_Auto_Speed4;

extern uint16_t Motor_Auto_Torque5;
extern uint16_t Motor_Auto_Turns5;
extern uint16_t Motor_Auto_Direction5;
extern uint16_t Motor_Auto_Speed5;
//////////////////////////////////////////////////
extern uint16_t Motor_Driver_MotorType;
extern uint16_t Motor_Driver_Direction;
extern uint16_t Motor_Driver_Accelerated;
extern uint16_t Motor_Driver_Decelerated;
extern uint16_t Motor_Driver_IKp;
extern uint16_t Motor_Driver_IKi;
extern uint16_t Motor_Driver_VKp;
extern uint16_t Motor_Driver_VKi;
extern uint16_t Motor_Driver_PKp;
//////////////////////////////////////////////////
//////////////////////////////////////////////////
///////////////////////////////////////////////////
extern uint16_t Var_Message_Alarm;

extern int16_t ModBus_RegisterData[1500];

extern uint16_t Flag_Motor_Motion;
extern uint8_t  RS485_Message[200];  
extern uint8_t  CAN_Message[10];  
extern uint16_t Timer2_Tick;
extern uint8_t  RS485_ReceiveEnd;
extern uint8_t  RS485_RxMessageCnt;
extern uint8_t  RS485_ReceiveFlag;
extern uint8_t  RS485_CheckFlag;
extern uint8_t  RS485_SetFlag;
extern uint8_t  CRC_L;
extern uint8_t  CRC_H;
extern uint32_t P1_RunFlag;
extern uint32_t R1_RunFlag;
extern uint32_t P2_RunFlag;
extern uint32_t R2_RunFlag;

extern uint16_t  SaveFlag;
extern uint16_t ResetFlag;
extern int32_t nowposition;
extern uint32_t nowtorque;
extern uint32_t nowspeed;
extern uint16_t TorqueArr;
extern uint16_t ReturnT;
extern uint16_t ReturnT1;
extern uint16_t turnT1;
extern uint16_t turnT2;
extern uint16_t turnT3;
extern uint16_t turnT4;
extern uint16_t turnT5;
extern uint16_t turnT6;
extern uint16_t turnT7;
extern uint16_t turnT8;
extern uint16_t turnT9;
extern uint16_t turnT10;
extern uint8_t Position_Arr;

extern uint16_t M2845_Speed500_Torque[101];
extern uint16_t M2845_Speed1000_Torque[101];
extern uint16_t M2845_Speed1500_Torque[101];
extern uint16_t M2845_Speed2000_Torque[101];

extern uint16_t M4260_Speed800_Torque[101];
extern uint16_t M4260_Speed1000_Torque[101];
extern uint16_t M4260_Speed1500_Torque[101];
extern uint16_t M4260_Speed2000_Torque[101];

extern uint16_t M5776_Speed500_Torque[101];
extern uint16_t M5776_Speed1000_Torque[101];
extern uint16_t M5776_Speed1500_Torque[101];
extern uint16_t M5776_Speed2000_Torque[101];

extern uint16_t M57112_Speed500_Torque[101];
extern uint16_t M57112_Speed1000_Torque[101];
extern uint16_t M57112_Speed1500_Torque[101];
extern uint16_t M57112_Speed2000_Torque[101];
extern uint32_t SaveTime;
uint16_t SetTorque(int16_t TorqueVal, uint16_t SpeedVal);
uint16_t ReturnTorque(uint16_t TorqueVal);
#endif
